package com.me.jingdongshop.ui.holder;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.me.common.ui.BaseAdapterRV;
import com.me.common.ui.BaseHolderRV;
import com.me.jingdongshop.R;
import com.me.jingdongshop.model.bean.ProductList;
import com.me.jingdongshop.model.protocol.IHttpService;
import com.me.jingdongshop.ui.activity.GoodsDetailActivity;
import com.me.jingdongshop.ui.activity.ProductlistActivity;
import com.squareup.picasso.Picasso;

/**
 * Created by Tm on 2017/5/8.
 */

public class ProductRVHolder extends BaseHolderRV<ProductList.ProductListBean> {

    private ImageView iconRv;
    private TextView title;
    private TextView tvPrice;
    private ImageView imgSelf;
    private TextView tvComment;
    private TextView tvDelivery;



    public ProductRVHolder(Context context, ViewGroup parent, BaseAdapterRV adapter, int itemType, int layoutId) {
        super(context, parent, adapter, itemType, layoutId);
    }

    @Override
    public void onFindViews(View itemView) {

        iconRv = (ImageView) itemView.findViewById(R.id.icon_rv);
        title = (TextView) itemView.findViewById(R.id.title);
        tvPrice = (TextView) itemView.findViewById(R.id.tv_price);
        imgSelf = (ImageView) itemView.findViewById(R.id.img_self);
        tvComment = (TextView) itemView.findViewById(R.id.tv_comment);
        tvDelivery = (TextView) itemView.findViewById(R.id.tv_delivery);


    }

    @Override
    protected void onRefreshView(ProductList.ProductListBean bean, int position) {
        String url = IHttpService.HOST_URL+ bean.getPic();
        Picasso.with(context).load(url).into(iconRv);
        title.setText(bean.getName());
        tvPrice.setText("$"+bean.getPrice());
        tvComment.setText(bean.getCommentCount()+"条评价");

    }

    @Override
    protected void onItemClick(View itemView, int position, ProductList.ProductListBean bean) {
        super.onItemClick(itemView, position, bean);
        Intent intent = new Intent((ProductlistActivity)context, GoodsDetailActivity.class);
        //商品的Id
        intent.putExtra("id",bean.getId());
        context.startActivity(intent);

    }
}
